@nadeshikon/plugin-nextjs
Version:
Run Next.js seamlessly on Netlify
24 lines (20 loc) • 574 B
JavaScript
export default async (req, res) => {
// Respond with JSON
res.setHeader('Content-Type', 'application/json')
// Get the ID of the show
const { query } = req
const { id } = query
// Get the data
const fetchRes = await fetch(`https://api.tvmaze.com/shows/${id}`)
const data = await fetchRes.json()
// If show was found, return it
if (fetchRes.status == 200) {
res.status(200)
res.json({ show: data })
}
// If show was not found, return error
else {
res.status(404)
res.json({ error: 'Show not found' })
}
}